package com.fiveflavors.suittar.gui.mainpanel.view;

import java.util.HashMap;

public class SuittarTimeLineViewManager {
	
	public static final String VIEWTYPE_PUBLIC = "Public";
	public static final String VIEWTYPE_PROFILE = "Profile";
	public static final String VIEWTYPE_FRIENDS = "Friends";
	public static final String VIEWTYPE_REPLIES = "Replies";	

	private static HashMap<String,SuittarTimeLineView> timeLineViewMap = new HashMap<String,SuittarTimeLineView>();
	private static final String PACKAGE_NAME = "com.fiveflavors.suittar.gui.mainpanel.view.";
	
	public static SuittarTimeLineView getSuittarTimeLineView(SuittarTimeLineViewBean timeLineViewBean) {

		String view = timeLineViewBean.getView();
		SuittarTimeLineView timeLineView = createSuittarTimeLineView(view);
		timeLineView.setSuitterTimeLineViewBean(timeLineViewBean);
		return timeLineView;
	}
	
	private static SuittarTimeLineView createSuittarTimeLineView(String view) {

		SuittarTimeLineView suittarTimeLineView = null;

		if (timeLineViewMap.containsKey(view)) {
			suittarTimeLineView = timeLineViewMap.get(view);
		}
		else {
			String className = PACKAGE_NAME + "Suittar" + view + "TimeLineView";
			try {
				suittarTimeLineView = (SuittarTimeLineView)Class.forName(className).newInstance();				
				timeLineViewMap.put(view,suittarTimeLineView);
			}
			catch (Exception e) {
				Exception e2 = new Exception("Class " + className + " has not found.",e);
				e2.printStackTrace();
			}
		}
		
		return suittarTimeLineView;
	}

}
